package com.ryskoo.permission.role.repository;

import com.ryskoo.framework.core.repository.BasicJPAImpl;
import com.ryskoo.permission.role.domain.RolePO;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class RoleJPAImpl extends BasicJPAImpl<RolePO> implements IRoleRepository {

	/**
	 * 删除角色信息以及角色与权限的关联关系，支持批量删除
	 *
	 * @param managerId 管理员id {@link String}
	 * @return 管理员拥有的角色列表 {@link List}&lt;{@link RolePO}&gt;
	 */
	@Override
	public List<RolePO> getRoleByManagerId(String managerId) {
		String sql = "select role.* from PMS_ROLE role left join PMS_MANAGER_ROLE_REL rel on role.uuid = rel.role_id where rel.manager_id = :managerId";
		Query query = this.getH4Session().createSQLQuery(sql).addEntity(RolePO.class);
		query.setString("managerId", managerId);
		return query.list();
	}
}
